import java.util.Scanner;

/**
 * 
 * @author Rahony
 * @author Jhonatan
 * 
 * Problema H da prova de 2007
 * 
 */
public class varetas {
	
	public static void main(String[] args) {
//		try {
//			System.setIn(new FileInputStream("in/2007/vareta.txt"));
//		} catch (IOException e) {}
		
		Scanner scanner = new Scanner(System.in);
		String linha;
		String[] dados;
		while (true) {
			linha = scanner.nextLine();
			if (linha.equals("0")) break;
			boolean sobro = false;
			int rects = 0;
			
			int n = Integer.parseInt(linha);
			for (int i = 0; i < n; i++) {
				int v = Integer.parseInt(scanner.nextLine().split(" ")[1]);
				rects += v / 4;
				if (v % 4 >= 2) {
					if (sobro) {
						rects++;
						sobro = false;
					} else {
						sobro = true;
					}
				}
			}
			System.out.println(rects);
		}
	}

}
